Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 4 - Commands


Using Results

The result of a command is the value generated when the command is executed. You can display the result of a command in the Script Editor. For example, if you run the following script,

tell front document of application "Scriptable Text Editor"   move word 1 to end of paragraph 1
end tell
and then choose Show Result from the Controls menu in the Script Editor, you'll see a value such as

word 32 of front document of application "Scriptable Text Editor"
You can use a command that returns a result as a value. For example, the Count command in the following statement returns a value: the number of words in the third paragraph.

count words in paragraph 3
You can use this statement anywhere a value is required by enclosing the statement in parentheses. For example, the following statement sets the value of numWords to the value returned by the Count command.

set numWords to (count words in paragraph 3)
In addition to displaying the result of a command in the result window, AppleScript puts the result into a predefined variable called result. The value remains there until the next command is executed. If the next command does not return a result, the value of result is undefined. The following two commands show how to use the result variable to set the value of numWords to the value returned by the Count command:

count words in paragraph 3
set numWords to result
When a direct parameter specifies more than one object, the result is a list that contains a value for each object that was handled. Here is an example of a command whose result is a list:

get paragraphs 1 thru 3 of first document
The result is a list of strings similar to the following. The first string is the value of the first paragraph, the second string is the value of the second paragraph, and the third string is the value of the third paragraph.

{"This is paragraph one.", "This is paragraph two." ¬
   "This is paragraph three."}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996